<div id="addAuthoritiesContent" class="hidden"></div>
<div id="data-tree">
    <ul>
        <li id="_all" data-jstree='{"icon":"iconfont1 icon-quanbu","opened":true,"selected":false}'>
            全部
            <ul>
                <li id="admin:index"
                        data-jstree='{"icon":"iconfont1 icon-guanlizhongxin","selected":[#if content?? && content.authorities?seq_contains("admin:index")]true[#else]false[/#if] }'>
                    管理中心
                </li>
                <li id="admin:main"
                        data-jstree='{"icon":"iconfont1 icon-zhuyemianban","selected":[#if content?? && content.authorities?seq_contains("admin:main")]true[#else]false[/#if] }'>
                    主页面板
                </li>
                <li id="admin:upload"
                        data-jstree='{"icon":"iconfont icon-upload","selected":[#if content?? && content.authorities?seq_contains("admin:upload")]true[#else]false[/#if] }'>
                    文件上传
                </li>

                <li id="_profile"
                        data-jstree='{"icon":"iconfont1 icon-gerenzhanghu","selected":false}'>
                    个人账户
                    <ul>
                        <li id="profile:modifyPassword"
                                data-jstree='{"icon":"none","selected":[#if content?? && content.authorities?seq_contains("profile:modifyPassword")]true[#else]false[/#if] }'>
                            修改密码
                        </li>
                        <li id="profile:update"
                                data-jstree='{"icon":"none","selected":[#if content?? && content.authorities?seq_contains("profile:update")]true[#else]false[/#if] }'>
                            修改基本信息
                        </li>

                    </ul>
                </li>
            </ul>
            [#include "/admin/admin/role/perms/setting.ftl" /]
        </li>
    </ul>
</div>

<script>
    $().ready(function () {
        var $saveOrUpdateForm = $("#saveOrUpdateForm");

        var addAuthoritiesTemplate = _.template($("#addAuthoritiesTemplate").html());
        var $addAuthoritiesContent = $("#addAuthoritiesContent");

        $saveOrUpdateForm.submit(function () {
            var treeNode = $('#data-tree').jstree(true).get_checked(true);
            var ids = [];
            $.each(treeNode, function (i, n) {
                if (n.id.indexOf("_") === -1) {
                    ids.push(n.id);
                }
            });

            $addAuthoritiesContent.html(addAuthoritiesTemplate({
                ids: ids
            }));
        });

        $('#data-tree').jstree({
            'core':{
                expand_selected_onload:false,
            },
            "checkbox": {
                cascade_to_disabled: false,
                keep_selected_style: false,
            },

            "plugins": ["wholerow", "checkbox",]
        });

    });
</script>